package focus

import (
	"api/config/code"
	"api/libs/api"
	"fmt"
	"gitee.com/dreamwood/ez/server"
	"time"
)

type FocusApi struct {
	api.BaseApi
}

func init() {
	t := new(FocusApi)
	t.RoutePrefix = fmt.Sprintf("/crm/admin/%s", "Order")
	t.AddRoute("/focus/count", t.FocusCountAction)
}

type counter struct {
	Title    string      `json:"title"`
	Data     interface{} `json:"data"`
	UpdateAt time.Time   `json:"updateAt"`
}

func (f FocusApi) FocusCountAction(operation *server.Operation) {
	this := f.TakeOver(operation)
	key := this.Get("key").IsString()
	if key == "" {
		this.ReturnError(code.Error, "Key 不能为空", "")
		return
	}

	this.ReturnSuccess("OK", counter{
		Title:    "计数器",
		Data:     "1001",
		UpdateAt: time.Now(),
	})

}
